home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / recio212.zip / rbput.c < prev    next >
C/C++ Source or Header  |  1995-01-29  |  3KB  |  91 lines

  1. /*****************************************************************************
  2.    MODULE: rbput.c
  3.   PURPOSE: recio character delimited integral number output functions
  4. COPYRIGHT: (C) 1994-1995, William Pierpoint
  5.  COMPILER: Borland C Version 3.1
  6.        OS: MSDOS Version 6.2
  7.   VERSION: 2.12
  8.   RELEASE: January 29, 1995
  9. *****************************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "recio.h"
  16.  
  17. extern int _risready(REC *rp, int mode);
  18. extern int _rputc(REC *rp, int ch);
  19.  
  20. #define rfp(rp)          ((rp)->r_fp)
  21. #define rcol(rp)         ((rp)->r_colno)
  22. #define rfldch(rp)       ((rp)->r_fldch)
  23. #define rflags(rp)       ((rp)->r_flags)
  24.  
  25. #define ulong            unsigned long
  26. #define UNSIGNED         0
  27. #define SIGNED           1
  28.  
  29. /****************************************************************************/
  30. static void                  /* returns nothing                             */
  31.     _rbputl(                 /* output integral number to record stream     */
  32.         REC *rp,             /* pointer to record stream                    */
  33.         int  base,           /* base (radix) (2 to 36)                      */
  34.         int  sign,           /* signed number (1=signed; 0=unsigned)        */
  35.         long num)            /* number to put to stream                     */
  36. /****************************************************************************/
  37. {
  38.     if (_risready(rp, R_WRITE)) { 
  39.         if (base >= 2 && base <= 36) { 
  40.             rfldno(rp)++;
  41.             rflags(rp) &= ~_R_TXT;
  42.  
  43.             /* if not first field, put field separator if not null */
  44.             if (rfldno(rp) > 1 && rfldch(rp)) { 
  45.                 if (_rputc(rp, rfldch(rp))) goto done; 
  46.             }
  47.  
  48.             /* based on sign, select conversion function */
  49.             if (sign) {
  50.                 ltoa(num, _r_nsbuf, base);
  51.             } else {
  52.                 ultoa((ulong)num, _r_nsbuf, base);
  53.             }
  54.  
  55.             /* output converted string */
  56.             if (fputs(_r_nsbuf, rfp(rp)) != EOF) {
  57.                 rcol(rp) += strlen(_r_nsbuf); 
  58.             } else { 
  59.                 rseterr(rp, R_ENOPUT); 
  60.             } 
  61.  
  62.         } else {
  63.             rseterr(rp, R_EINVAL);
  64.         }
  65.     } 
  66. done:
  67. }
  68.  
  69. /****************************************************************************/
  70. /* character delimited integral number output functions                     */
  71. /****************************************************************************/
  72. void rbputi(REC *rp, int base, int num)
  73. {
  74.     _rbputl(rp, base, SIGNED, (long) num);
  75. }
  76.  
  77. void rbputui(REC *rp, int base, unsigned int num)
  78. {
  79.     _rbputl(rp, base, UNSIGNED, (long) num);
  80. }
  81.  
  82. void rbputl(REC *rp, int base, long num)
  83. {
  84.     _rbputl(rp, base, SIGNED, num);
  85. }
  86.  
  87. void rbputul(REC *rp, int base, unsigned long num)
  88. {
  89.     _rbputl(rp, base, UNSIGNED, (long) num);
  90. }
  91.